'use strict';

module.exports = app => {
  const mongoose = app.mongoose;
  const Schema = mongoose.Schema;

  const RoutersSchema = new Schema({
    methods: String,
    name: {
      type: String,
      index: 1,
    },
    path: String,
    ids: String,
    createAt: {
      type: Date,
      default: Date.now,
    },
  });
  RoutersSchema.pre('save', function(next) {
    this.ids = `${this.methods}_${this.path.substring(5)}`;
    next();
  });
  return mongoose.model('routers', RoutersSchema, null, { cache: false });
};
